var mno="null";
var pages;
//检查登录信息
	    $(function(){$.post("../../menberInfo/checkLogin", null , function(data){
	    	var str ='';
	    	
	    	if(!data.code){
	    		mno=data.mno;
	    		console.log("mno:"+mno);
	    		str+='<div class="login_info fl">';
	    		str+='欢迎：<em>'+data.nickName+'</em>';
	    		str+='</div> ';
	    		findMenber();
	    		getPage();
	    		getOrderByPage(1);
	    	} else {				    		
	    		str+='<a href="register.html">注册</a>';
	    		str+='</div>';
	    	}
	    	str+='<div class="user_link fl">';
	    	str+='<span> | </span>';
	    	str+='<a href="user.html">用户中心</a>';
	    	str+='<span> | </span>';
	    	str+='<a href="cart.html">我的购物车</a>';
	    	str+='<span> | </span>';
	    	str+=' <a href="order.html">我的订单</a>  </div> ';
	    	$("#stu_name").html(str);
	    }, "json");
	    })
	  function show(obj,cla){
		  switch(cla){
		  	case "info_con" : 
		  		$(".info_con").css("display",'block'); 
		  		$(".order_icon").css("display",'none');
		  		$(".site_con").css("display",'none');
		  		$("#info").attr("class",'active'); 
		  		$("#order").attr("class",''); 
		  		$("#addr").attr("class",''); 
		  		findMenber();
		  	break;
		  	case "order_icon" : 
		  		$(".info_con").css("display",'none'); 
				$(".order_icon").css("display",'block');
				$(".site_con").css("display",'none');
				$("#info").attr("class",''); 
		  		$("#order").attr("class",'active'); 
		  		$("#addr").attr("class",''); 

			break;
		  	case "site_con" : 
		  		$(".info_con").css("display",'none');
				$(".order_icon").css("display",'none');
				$(".site_con").css("display",'block');
				$("#info").attr("class",''); 
		  		$("#order").attr("class",''); 
		  		$("#addr").attr("class",'active'); 
		  		findAddr();
			break;
		  }
	  }
	  function findMenber(){
		  $.post("../../menberInfo/checkLogin", null ,function(data){			   
			  var str="<li>用户名称：<span>"+data.realName+"</span> </li>";
			  str+="<li>联系方式：<span>"+data.tel+"</span></li>";
			  str+="<li>注册日期：<span>"+data.regDate+"</span></li>";
		    $("#menber").html(str);
		  },"json");
	  }
	  
	  function findAddr(){
		  $.post("../../addrInfo/finds", {mno:mno} ,function(data){			   
			  var str="<dt>当前地址</dt>";
			  for(var i=0;i<data.length;i++){
				  if(data[i].flag==1){
					  str+="<dd>收件对象：<span>"+data[i].name+"</span></dd>";
					  str+="<dd>收货地址：<span>"+data[i].province+" "+data[i].city+" "+data[i].area+" "+data[i].addr+"</span></dd>";
					  str+="<dd>电话号码：<span>"+data[i].tel+"</span></dd>";
				  }
			  }		  
		    $("#addr").html(str);
		  },"json");
	  }
	  
	  function find(){
			var str=$("#inp").val();
			$.post("../../goodsInfo/find",{str:str},function(data){
				console.log(data);
				if(data==null){
					alert("抱歉,没有该商品...");
					console.log("抱歉,没有该商品...");
				}else{					
					location.href="../../details.html?gno="+data.gno;
				}
			},"json");
		}
	  //得到订单的页数
	  function getPage(){
		  var str='<ul>';
		  $.post("../../orderInfo/getPage", {mno:mno}, function(data){
			  for(var i=1;i<=data;i++){		
				  if(i==1){
					  str+='<li><a href="javascript:getOrderByPage('+i+')" class="active" id="'+i+'">'+i+'</a></li>'; 
				  }else{
					  str+='<li><a href="javascript:getOrderByPage('+i+')"  class=""  id="'+i+'">'+i+'</a></li>';
				  }				  
			  }
			  str+='</ul>';
			  $("#page").html(str);
		  },"json");
		  
	  }
	  
      
     
	  
	  function getOrderByPage(page){
			var str='';
			if(page!=pages){
				$("#"+page+"").attr("class",'active'); 
		  		$("#"+pages+"").attr("class",''); 
			
				$.post("../../orderInfo/getOrderByPage", {mno:mno,page:page}, function(data){
					var ono=0;
					var total=0;
					for(var i=0;i<data.length;i++){			
						var n=1;			
						if(ono!=data[i].ono){
							str+='<ul class="order_list_th w978 clearfix">';
							str+='<li class="col01" >'+data[i].odate+'</li>';
							str+='<li class="col02">订单号：'+data[i].ono+'</li>';
							if(data[i].status==0){//未支付																												
								str+='<li class="col02 stress">未支付</li> </ul>';
							}else{
								str+='<li class="col02 stress">已支付</li> </ul>';
							}
							ono=data[i].ono;
							str+='<table class="order_list_table w980"> <tbody> <tr> <td width="55%">';
	
							for(var j=0;j<data.length;j++){
								if(ono==data[j].ono){
									str+=' <ul class="order_goods_list clearfix">';
									str+='<li class="col01"><img src="../../'+data[j].pics+'"></li>';
									str+='<li class="col02">'+data[j].gname+'<em>'+data[j].prices+'元/'+data[j].unit+'</em></li>	';
									str+='<li class="col03">'+data[j].nums+'</li>';
									total=parseInt(data[j].prices*data[j].nums);
									str+='<li class="col04">'+total+'元</li> </ul>';
		
								}
							}
							str+='</td> <td width="15%">'+data[i].price+'元</td>';
							if(data[i].status==0){//未支付																												
								str+='<td width="15%">待付款</td>';
								str+='<td width="15%"><a href="../../index.jsp?price='+data[i].price+'&ono='+data[i].ono+'" class="oper_btn">去付款</a></td>';
							}else{
								str+='<td width="15%">已付款</td>';
								str+='<td width="15%"><a href="javascript:void(0)" class="oper_btn">已完成</a></td>';
							}
							str+='</tr> </tbody> </table>';						
						}	
					}
					$("#orderinfo").html(str);
				},"json");
			}
			pages=page;
		}
	  
	  
	  
	  
		
		
				
	

	
		
			
				
										
						
						
						
							
					
					
				
				
				
				
			
		
	